﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UDDL.Model;
using System.IO;

namespace UDDL.CodeGeneration.CPP
{
	class CppNamespace : CppItem
	{
		internal CppNamespace(CppNamespace parent, Namespace source)
			: base(source)
		{
			Parent = parent;
			foreach (Namespace ns in source.SubNamespaces)
			{
				m_subNamespaces.Add(new CppNamespace(this, ns));
			}
			foreach (Entity entity in source.Entities)
			{
				m_entities.Add(new CppEntity(this, entity));
			}

			if (Parent != null)
			{
				if (Parent.Filename == null)
				{
					Filename = Name;
				}
				else
				{
					Filename = Path.Combine(Parent.Filename, Name);
				}
			}
		}

		public void CollectEntities(List<CppEntity> entities)
		{
			entities.AddRange(m_entities);
			foreach (CppNamespace ns in m_subNamespaces)
			{
				ns.CollectEntities(entities);
			}
		}


		public String Filename { get; private set; }
		public CppNamespace Parent { get; internal set; }
		private List<CppNamespace> m_subNamespaces = new List<CppNamespace>();
		private List<CppEntity> m_entities = new List<CppEntity>();
	}
}
